home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.9 KB | 191 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGrObj.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWGROBJ_H
- #include "FWGrObj.h"
- #endif
-
- #ifndef FWGRGLOB_H
- #include "FWGrGlob.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgraphx
- #endif
-
- FW_DEFINE_CLASS_M0(FW_CGraphicCountedPtrRep)
- FW_DEFINE_CLASS_M0(FW_CGraphicCountedPtr)
-
- //========================================================================================
- // class FW_CGraphicCountedPtrRep
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtrRep::FW_CGraphicCountedPtrRep
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicCountedPtrRep::FW_CGraphicCountedPtrRep() :
- fRefCount(0)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtrRep::~FW_CGraphicCountedPtrRep
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicCountedPtrRep::~FW_CGraphicCountedPtrRep()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtrRep::Purge
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicCountedPtrRep::Purge()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtrRep::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicCountedPtrRep::Write(FW_CWritableStream& archive, const void* rep)
- {
- ((FW_CGraphicCountedPtrRep*)rep)->Flatten(archive);
- }
-
- //========================================================================================
- // class FW_CGraphicCountedPtr
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::~FW_CGraphicCountedPtr
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicCountedPtr::~FW_CGraphicCountedPtr()
- {
- FW_START_DESTRUCTOR
- DownCount();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::FW_CGraphicCountedPtr
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicCountedPtr::FW_CGraphicCountedPtr() :
- fRep(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::FW_CGraphicCountedPtr
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicCountedPtr::FW_CGraphicCountedPtr(const FW_CGraphicCountedPtr& other) :
- fRep(other.fRep)
- {
- UpCount();
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::UpCount
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicCountedPtr::UpCount()
- {
- if (fRep)
- fRep->IncrementRefCount();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::DownCount
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicCountedPtr::DownCount()
- {
- if (fRep && !fRep->Release())
- delete fRep;
- // It is not necessary to set fRep to NULL. To see why, see how DownCount is used above.
- // In all cases, fRep is either immediately reset, or the instance is being destroyed.
- // Note too that DownCount is private.
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::SetRep
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicCountedPtr::SetRep(FW_CGraphicCountedPtrRep* rep)
- {
- if (fRep != rep)
- {
- DownCount();
- fRep = rep;
- UpCount();
- }
- }
-
- //========================================================================================
- // Global operators << and >>
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // operator>>
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CReadableStream& operator>>(FW_CReadableStream& archive, FW_CGraphicCountedPtr &object)
- {
- FW_CGraphicCountedPtrRep* rep = NULL;
-
- void * voidPtr = (void *)rep;
- FW_CDynamicArchiver::InputObject(archive, voidPtr);
- rep = (FW_CGraphicCountedPtrRep*)voidPtr;
-
- FW_ASSERT(rep != NULL); // Should be an exception???
-
- object.SetRep(rep);
-
- return archive;
- }
-
- //----------------------------------------------------------------------------------------
- // operator<<
- //----------------------------------------------------------------------------------------
-
- FW_FUNC_ATTR FW_CWritableStream& operator<<(FW_CWritableStream& archive, const FW_CGraphicCountedPtr &object)
- {
- FW_CDynamicArchiver::OutputObject(archive, object.GetRep(), FW_CLASSNAME_FROM_POINTER(object.GetRep()));
- return archive;
- }
-
-
-